package MapAndSet;

import java.util.*;

public class Test {
    public static void main(String[] args) {
        //找到这组数据中，第一个重复的数字
        int[] array ={1,2,2,3,3,4,5,6,7,8,9,12,1,8,7,9,6,5,4,13,16,53,66};
        HashSet<Integer> set = new HashSet<>();
        for (int i = 0; i < array.length; i++) {
            if (! set.contains(array[i])){
                set.add(i);
            }else {
                System.out.println(array[i]);
                return;
            }
        }
        //去除重复的数字
        /*int[] array ={1,2,2,3,3,4,5,6,7,8,9,12,1,8,7,9,6,5,4,13,16,53};
        HashSet<Integer> set = new HashSet<>();
        for (int i = 0; i < array.length; i++) {
            set.add(array[i]);
        }
        System.out.println(set);*/
    }
    public static void main4(String[] args) {
        Set<String> set = new TreeSet<>();
        set.add("nan");
        set.add("xing");
        set.add("tao");
        set.add("jv");
        System.out.println(set.size());
        System.out.println(set);
        System.out.println(set.contains("nan"));
        System.out.println(set.contains("yi"));
        System.out.println(set.contains("xing"));
        Iterator<String> iterator = set.iterator();
        while (iterator.hasNext()){
            System.out.print(iterator.next()+" ");
        }
        System.out.println();
    }
    public static void main3(String[] args) {
        Map<String,String> map = new TreeMap<>();
        map.put("齐天大圣","孙悟空");
        map.put("灌江口话事人","杨戬");
        map.put("双花红棍","哪吒");
        map.put("未来佛","弥勒");
       String  str = map.put("现在佛","如来");
        System.out.println(map.size());//5
        System.out.println(map.get("齐天大圣"));//孙悟空
        System.out.println(map.getOrDefault("双花红棍","哪吒"));//哪吒
        System.out.println(map.containsKey("未来佛"));//true
        System.out.println(map.containsValue("杨戬"));//true
        for (String s: map.keySet()){
            System.out.print(s+" ");//双花红棍 未来佛 灌江口话事人 现在佛 齐天大圣
        }
        System.out.println();
        System.out.println("========");
        for (String s: map.values()){
            System.out.print(s+" ");//哪吒 弥勒 杨戬 如来 孙悟空
        }
        System.out.println();
        System.out.println("======");
        for (Map.Entry<String,String>entry:map.entrySet()){
            System.out.println(entry.getKey()+"---->"+entry.getValue());
        }
        System.out.println();
    }
    public static void main2(String[] args) {
        TreeMap<String,Integer> treeMap = new TreeMap<>();
        treeMap.put("nan",3);
        treeMap.put("jia",9);
        treeMap.put("ma",5);
        Integer ret =  treeMap.get("nan");
        System.out.println(ret);
        Integer val = treeMap.get("nan");
       Integer n =  treeMap.getOrDefault("nan",3);
        System.out.println(n);
        Set<Map.Entry<String,Integer>> entrySet = treeMap.entrySet();
        for (Map.Entry<String,Integer>entry: entrySet){
            System.out.println("key:"+entry.getKey()+" val "+entry.getValue());
        }
        Set<String> set = treeMap.keySet();
        treeMap.values();
    }
    public static void main1(String[] args) {
        BinarySearchTree bst = new BinarySearchTree();
        bst.insert(5);
        bst.insert(3);
        bst.insert(7);
        bst.insert(2);
        bst.insert(9);
        BinarySearchTree .TreeNode ret = bst.search(9);
        System.out.println(ret.val);
        bst.remove(5);
    }
}
